package com.star.cat.persitent.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.star.cat.common.vo.CacheNode;
import com.star.cat.common.vo.CacheVo;
import com.star.cat.persitent.service.PerManager;

/**
 * 持久化接口
 * @author liguangcai
 * @date 2019/07/16 09:46
 */
@Controller
@RequestMapping("/persitent")
public class PersitentController {
	
	@Autowired
	private PerManager perManager;
	
	@RequestMapping("/")
    public String index(){
        return "/res/per_index.html";
    }
	
	@ResponseBody
	@RequestMapping("/tree/keys")
	public List<CacheNode> tree(){
		return perManager.tree();
	}
	
	@ResponseBody
	@RequestMapping("/values")
	public Map<?, ?> allValues(){
		return perManager.findAll();
	}
	
	/**
     * 根据key获取相关信息
     * @param key
     * @return
     */
    @ResponseBody
    @RequestMapping("/key")
    public CacheVo findByKey(String key){
        return perManager.findByKey(key);
    }
    
    /**
     * 根据key删除
     * @param key
     */
    @ResponseBody
    @RequestMapping("/remove")
    public void removeByKey(String key){
    	perManager.removeByKey(key);
    }
    
    /**
     * 删除所有
     */
    @ResponseBody
    @RequestMapping("/removeAll")
    public  void removeAll(){
    	perManager.removeAll();
    }
    
    /**
     * 增加时长
     * @param key
     * @param time
     */
    @ResponseBody
    @RequestMapping("/extend")
    public void extendTime(String key,Long time) {
    	perManager.extendTime(key,time);
    }
	
	
}























